angular.module('starter.controllers', [])

    .controller('DashCtrl', function ($scope, $stateParams, Chats, $ionicSlideBoxDelegate) {
        $scope.chats = Chats.all();
        $scope.remove = function (chat) {
            Chats.remove(chat);
        }
        $scope.pagerClick = function (index) {
            $ionicSlideBoxDelegate.slide(index);
        }
        $scope.doRefresh = function () {
            setTimeout(function () {
                $scope.$broadcast('scroll.refreshComplete');
            }, 2000);
        }

    })
    .controller('ChatsCtrl', function ($scope, Chats) {
        $scope.chats = Chats.all();
        $scope.remove = function (chat) {
            Chats.remove(chat);
        }
    })
    .controller('ChatDetailCtrl', function ($scope, $stateParams, Chats) {
        $scope.chat = Chats.get($stateParams.chatId);
    })
    .controller('AccountCtrl', function ($scope, $ionicActionSheet, $cordovaDialogs, $cordovaCamera) {
        $scope.settings = {
            enableFriends: true
        };
        $scope.addAttachment = function () {
            var options = {
                quality: 50,
                allowEdit: true,
                targetWidth: 100,
                targetHeight: 100,
                saveToPhotoAlbum: false
            };
            $ionicActionSheet.show({
                buttons: [
                    {text: '相机'},
                    {text: '图库'}
                ],
                cancelText: '关闭',
                cancel: function () {
                    return true;
                },
                buttonClicked: function (index) {
                    switch (index) {
                        case 0:
                            $cordovaCamera.getPicture(options).then(function (imageData) {
                                $cordovaDialogs.alert(imageData, "hello");
                                var image = document.getElementById('myPhoto');
                                image.src = "data:image/jpeg;base64," + imageData;
                                $cordovaDialogs.alert(image.src, "hello");
                            }, function (err) {
                                $cordovaDialogs.alert(err, "hello");
                            });
                            break;
                        case 1:
                            $cordovaDialogs.confirm("你好", "1233", ['OK1', 'Cancel']);
                            break;
                        default:
                            break;
                    }
                    return true;
                }
            });
        }


    })
;

